import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    islogin: sessionStorage.getItem('islogin'),
    // 用户信息
    user: sessionStorage.getItem('user'),
    person_name: sessionStorage.getItem('person_name'),
    id: sessionStorage.getItem('id'),
    money: 0,
    booktpid: 0,
  },
  // 要修改state中的值, 必须使用 mutations 中的方法进行
  // mutation: 变化
  mutations: {
    updateUser(state, payload) {
      console.log('payload1', payload)
      state.islogin = true
      state.user = payload
      sessionStorage.setItem('islogin', true)
      sessionStorage.setItem('user', payload)
    },
    updatePname(state, payload) {
      console.log('payload2', payload)
      state.person_name = payload
      sessionStorage.setItem('person_name', payload)
    },
    updateUserId(state, payload) {
      state.id = payload
      sessionStorage.setItem('id', payload)
    },
    updateMoney(state, payload) {
      state.money = payload
    },
    updateBooktpid(state, payload) {
      state.booktpid = payload
    },
  },
  actions: {},
  modules: {},
})
